package com.example.pictureManage.util;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;

import java.util.HashMap;
import java.util.Map;

public class menuManage {
    private final ContextMenu contextMenu = new ContextMenu();
    private final Map<String, MenuItem> menuItems = new HashMap<>();

    /**
     * @author 郑伯洋
     * @param itemStr 菜单选项的内容
     * 用于增加菜单选项的内容
     * */
    public void addMenuItem(String itemStr){
        MenuItem menuItem = new MenuItem(itemStr);
        menuItems.put(itemStr,menuItem);
        contextMenu.getItems().add(menuItem);
    }
    /**
     * 设置菜单点击事件
     * */
    public void addHandler(String itemStr, EventHandler<ActionEvent> handler){
        if (menuItems.get(itemStr) == null){
            return;
        }
        menuItems.get(itemStr).setOnAction(handler);
    }

    public ContextMenu getContextMenu() {
        return contextMenu;
    }

    public Map<String, MenuItem> getMenuItems() {
        return menuItems;
    }
}
